package com.example.mysmall.mvp_rajava;

import android.content.Intent;

import com.example.mysmall.mvp_rajava.app.App;
import com.example.mysmall.mvp_rajava.base.BaseActivity;
import com.example.mysmall.mvp_rajava.base.BaseFragment;
import com.example.mysmall.mvp_rajava.injector.component.DaggerHomeComponent;
import com.example.mysmall.mvp_rajava.injector.modules.HomeModule;
import com.example.mysmall.mvp_rajava.manager.FragmentManager;
import com.example.mysmall.mvp_rajava.ui.modules.home.HomeFragment;
import com.example.mysmall.mvp_rajava.ui.modules.home.HomePresenter;

import javax.inject.Inject;

public class MainActivity extends BaseActivity {

    @Inject
    HomePresenter presenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void init() {
        HomeFragment homeFragment = (HomeFragment) FragmentManager.changeFragment(HomeFragment.class, R.id.mFragmentContianer, true, null, true);
        DaggerHomeComponent.builder()
                .homeModule(new HomeModule(homeFragment))
                .build()
                .inject(this);
    }
    @Override
    public void onBackPressed() {
        android.support.v4.app.FragmentManager.BackStackEntry entry = getSupportFragmentManager().getBackStackEntryAt(
                getSupportFragmentManager().getBackStackEntryCount() - 1);
        String simpleName = entry.getName();
        if ("HomeFragment".equals(simpleName)
                ) {
            finish();
        } else {
            if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
                getSupportFragmentManager().popBackStackImmediate();
                String name = getSupportFragmentManager().getBackStackEntryAt(
                        getSupportFragmentManager().getBackStackEntryCount() - 1).getName();
                App.lastFragment = (BaseFragment) getSupportFragmentManager().findFragmentByTag(name);
            }

        }

    }


}
